//
//  HttpBaseClient.m
//  Training
//
//  Created by michael shen on 15/6/17.
//  Copyright (c) 2015年 coolem. All rights reserved.
//

#import "HttpBaseClient.h"
#define ServerBaseAddress @"http:";

@implementation HttpBaseClient

+ (HttpBaseClient *)sharedClient{
    static HttpBaseClient *httpClient = nil;
    if (httpClient == nil) {
//        httpClient = [[[self class] alloc] initWithBaseURL:[NSURL URLWithString:@"http://www.baidu.com"]];
//        [httpClient.operationQueue setMaxConcurrentOperationCount:5];
//        httpClient.requestSerializer.stringEncoding = NSUTF8StringEncoding;
//        NSMutableSet *set = [NSMutableSet setWithSet:httpClient.responseSerializer.acceptableContentTypes];
//        [set addObject:@"text/html"];
//        [set addObject:@"text/plain"];
//        httpClient.responseSerializer.acceptableContentTypes = set;
        httpClient = [[self class] manager];
    }
    return httpClient;
}

- (void)requestWithRequest:(NSString *)request finish:(void (^)(AFHTTPRequestOperation *operation, NSError *error))block{
    [self GET:request parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        block(operation, nil);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        block(operation, error);
    }];
}

- (void)requestWithRequest:(NSString *)request method:(NSString *)method finish:(void (^)(AFHTTPRequestOperation *operation, NSError *error))block {
    if ([[method uppercaseString] isEqualToString:@"GET"]) {
        [self GET:request parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            block(operation, nil);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            block(operation, error);
        }];
    } else {
        [self requestWithRequest:request finish:block];
    }
}

@end
